import { validateNotJSkeyWord } from '../../../../../../../../common/utils/validate'
import { getApiList, getRuleList, getDictionaryTypeList } from '../../../../service'

let variableValidator = (rule, value, callback) => {
  const re = /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z\d_\u4e00-\u9fa5]*$/
  if (!re.test(value)) {
    callback(new Error('字段名必须以字母开头，且只能包含字母、数字、下滑线）'))
    return
  }
  if (!validateNotJSkeyWord(value)) {
    callback(new Error('不能使用js保留字段'))
    return
  }
  callback()
}
export default {
  labelWidth: '86px',
  gap: '12px',
  groupTheme: 'collapse',
  groups: [
    {
      title: '组件配置',
      columnsCount: 2,
      items: [
        {
          type: 'input',
          label: '标识',
          prop: 'componentId',
          readonly: true
        },
        {
          label: '绑定方法',
          prop: 'bindMethod',
          type: 'radio',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [
              {
                label: '字典',
                value: 1
              },
              {
                label: '输入',
                value: 2
              }
            ]
          }
        },
        {
          type: 'select',
          label: '关联字典',
          prop: 'propertyType',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getDictionaryTypeList()
            }
          },
          rules: [{ required: true, message: '请选择绑定值类型', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'bindSelect',
          label: '绑定值',
          prop: 'propertyName',
          config: {
            bindProp: 'propertyType',
            optionsValueKey: 'tagValue',
            optionsLabelKey: 'dicTagName',
            returnObject: false,
          },
          rules: [{ required: true, message: '请选择绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '绑定值',
          prop: 'propertyName',
          rules: [{ required: true, message: '请输入绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 2) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '名称',
          prop: 'name',
          rules: [{ required: true, message: '请输入控件名称', trigger: 'blur' }]
        },
        {
          type: 'input',
          label: '标签',
          prop: 'label'
        },
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: '自定义样式',
            language: 'css',
            height: '300px',
            lineNumbers: 'on',
            position: 'right'
          },
          prop: 'customStyle'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否必填',
            position: 'right'
          },
          label: '是否必填',
          prop: 'required'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否可见',
            position: 'right'
          },
          label: '是否可见',
          prop: 'isShowExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否存在',
            position: 'right'
          },
          label: '是否存在',
          prop: 'isExistExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            height: '300px',
            lineNumbers: 'on',
            title: '是否只读',
            position: 'right'
          },
          label: '是否只读',
          prop: 'isReadonlyExp'
        }
      ]

    }
  ]
}
